<template>
  <div class="detailPageImage">
    <div class="imageInfo">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>外观图片</span>
        </div>
        <el-row
          v-if="
            typeof formData.imageList != 'undefined' &&
            formData.imageList.length > 0
          "
        >
          <el-col
            :span="4"
            v-for="(item, index) in formData.imageList"
            :key="index"
            :offset="index > 0 ? 1 : 0"
          >
            <el-card :body-style="{ padding: '0px' }">
              <img :src="item.url" class="image" />
              <div style="padding: 14px">
                <el-tooltip class="item" effect="dark" placement="bottom">
                  <div slot="content">{{ item.name }}</div>
                  <div class="name">{{ item.name }}</div>
                  
                </el-tooltip>
                
                <div class="bottom clearfix">
                  <time class="time">{{ parseDate(currentDate) }}</time>
                  <hr />
                  <el-button
                    icon="el-icon-zoom-in"
                    @click="handlePictureCardPreview(item)"
                    circle
                  ></el-button>
                  <el-button
                    type="primary"
                    icon="el-icon-download"
                    @click="handlePictureDownload(item)"
                    circle
                  ></el-button>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
        <el-empty description="暂无图片" v-else></el-empty>
      </el-card>
    </div>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="" />
      <div class="text-center">
        <span>{{ dialogImageName }}</span>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { easyClone } from "@/util/index.js";
import { downloadRequest } from "@/api/api";
import { SelectData } from "@/mixins/select-data.js";
import { base } from "@/api/api";
import FileSaver from "file-saver";
export default {
  mixins: [SelectData],
  name: "DetailPageImage",
  props: {
    data: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      dialogImageUrl: "",
      dialogVisible: false,
      dialogImageName: "",
      formData: {},
      currentDate: new Date(),
    };
  },
  created() {
    console.log("imageList", this.formData);
  },
  methods: {
    handlePictureCardPreview(file) {
      this.dialogImageUrl = base + file.path;
      this.dialogVisible = true;
      this.dialogImageName = file.name;
    },
    handlePictureDownload(file) {
      console.log(file.name, file.path);
      var url = "/plan/download";
      var _this = this;
      let params = { filePath: file.path };
      let fileName = file.name;
      downloadRequest(url, params).then((res) => {
        let blob = new Blob([res.data]);
        FileSaver.saveAs(blob, fileName);
      });
    },
  },
  watch: {
    data: {
      handler(newValue) {
        this.formData = easyClone(newValue) || {};
        console.log("imageDetailxx", this.formData);
      },
      immediate: true,
      deep: true,
    },
  },
};
</script>
<style scoped>
.time {
  font-size: 13px;
  color: #999;
}
.name {
  text-overflow: ellipsis;
  overflow: hidden;
}
.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  height: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix span {
  float: left;
}
.clearfix:after {
  clear: both;
}
</style>